#include <bits/stdc++.h>

using namespace std;

class Solution {
   public:
    vector<string> summaryRanges(vector<int>& nums) {
        vector<string> ret;
        int l = 0;
        while (l < nums.size()) {
            int r = l;
            while (r < nums.size() - 1 && nums[r + 1] == nums[r] + 1) {
                r++;
            }
            if (r == l) {
                ret.push_back(to_string(nums[l]));
            } else {
                ret.push_back(to_string(nums[l]) + "->" + to_string(nums[r]));
            }
            l = r + 1;
        }
        return ret;
    }
};